/*
* ////////////////////////////////////////////////
*
* 开发者：AZPEP
* 友情链接：
*	-	B站：		零分的考卷			https://space.bilibili.com/257391258
*	-	Github：	AZPEP-BiliBili		https://github.com/AZPEP-BiliBili
*	-	Gitee：		AZPEP_BiliBili		https://gitee.com/AZPEP_BiliBili
*
* CopyRight AZPEP
*
* ////////////////////////////////////////////////
*/

#pragma once
#pragma execution_character_set("utf-8")

#include <Windows.h>
#include <vector>
#include <string>
#include <sstream>

#include "includes/AST_Errors.h"

#include "includes/LogModule.h"
#pragma comment(lib, "LogModule.lib")

#include "includes/ThrowError.h"
#pragma comment(lib, "ThrowError.lib")

#include "includes/MountESP.h"
#pragma comment(lib, "MountESP.lib")

#include "includes/dismapi.h"
#pragma comment(lib,"dismapi.lib")

#include "includes/SimpleDiskPartAPI.h"
#pragma comment(lib,"SimpleDiskPartAPI.lib")

#include "includes/CreateBcdBoot.h"
#pragma comment(lib,"CreateBcdStartup.lib")

// 日志句柄
inline ASTLOG_HANDLE LogHandle = 0;

// EFI 分配盘符表
inline std::vector<WCHAR> EspLetterList;

/// <summary>
/// EFI 分区对照地图
/// </summary>
typedef struct EfiPartitionMap {

	//盘符
	WCHAR Letter;

	//分区信息表
	SimpleEfiPartitionInformationW* PartitionInfo;
};

//版本号储存
typedef struct ProductVersion {
	//主版本号
	UINT Major;

	//次版本号
	UINT Minor;

	//生成版本号
	UINT Build;
};

//简略映像信息
typedef struct SimpleImageInfo {
	//索引号
	int Index;

	//映像名称
	std::wstring ImageName;

	//产品类型
	std::wstring EditionId;

	//映像描述
	std::wstring ImageDescription;

	//产品名称
	std::wstring ProductName;

	//操作系统版本
	ProductVersion Version;

	//映像大小
	UINT64 ImageSize;
};

//分区基本信息
typedef struct PartitionInfoW {
	//盘符
	WCHAR Letter;

	//分区总空间
	unsigned long long TotalSpace;
};

//文件复制信息
typedef struct CopyFileHandle {
	std::wstring Src;
	std::wstring Des;
};
// 程序运行目录
inline std::wstring ProgramPathW;

//是否为亮色模式
inline bool LightMode = true;

//EFI 信息表
inline std::vector<EfiPartitionMap*> EspInfomationList;

//系统分区盘符
inline WCHAR SystemPartitionLetter;

//系统分区总空间，以字节为单位
inline unsigned long long SystemPartitionTotalSpace;

//映像文件路径
inline std::wstring ImageFilePathW;

//存储Dism映像信息的列表
inline std::vector<SimpleImageInfo> SIIL;

//存储驱动器总大小的列表
inline std::vector<PartitionInfoW> PIWL;

//界面初始化是否完成
inline bool InitDone = false;

//程序运行路径，后不带反斜杠
inline std::wstring WorkDirPath;

/// <summary>
/// 初始化程序
/// </summary>
void Init();

#define _wstr2qstr(x) QString::fromLocal8Bit(_wstr2str(x))
#define _str2qstr(x) QString::fromLocal8Bit(x)
#define _wstr2str(x) wstring2string(x)
#define _str2wstr(x) string2wstring(x)
#define _qstr2str(x) *new std::string(x.toLocal8Bit())
#define _qstr2wstr(x) _str2wstr(_qstr2str(x))

std::wstring string2wstring(std::string str);
std::string wstring2string(std::wstring wstr);
size_t Replace(std::wstring& strValue, const std::wstring& strOld, const std::wstring& strNew);